<?php

namespace app\admin\controller;
use app\admin\model\ComplainMessage as ComplainMessageModel;
use think\Db;

class ComplainMessage extends Base {

    protected $complain_message_model;
    protected $region_model;

    public function _initialize() {
        parent::_initialize();
        $this->complain_message_model = new ComplainMessageModel();
        $this->assign('orderTypeList', order_type());
        $this->assign('appTypeList', ['0'=>'乘客','1'=>'司机']);
    }

    /**
     * 投诉配置列表
     * @param string
     * @param int
     * @return string
     */
    public function index() {
        $page = input('get.page');
        $limit = input('get.limit');
        if ($page && $limit) {
            $data = input('get.');
            $list = $this->complain_message_model->getListInfo($page, $limit, $data);
            echo json_encode($list);
            exit;
        }
        return $this->fetch();
    }

    //删除投诉配置
    /*public function del() {
        if (input('get.id')) {
            $id = input('get.id');
            $data = Db::name('cost_config')->where('id',$id)->update(['status'=>0]);
            if ($data) {
                exit(json_encode(['status' => 1, 'msg' => '删除成功']));
            } else {
                exit(json_encode(['status' => 0, 'msg' => '删除失败']));
            }
        } else {
            $this->error('不存在的费用信息', '', '', 1);
        }
    }*/

    //添加投诉信息
    public function add() {
        if (input('post.')) {
            $data = input('post.');
            $data['admin_id']   = session('admin_id');
            $data['admin_name'] = session('admin_name');
            $data['add_time']   = time();
            $complain_id = Db::name('complain_message')->insertGetId($data);
            if($complain_id){
                echo ajax_success('提交成功');
            }else{
                echo ajax_error('提交失败');
            }
        } else {
            return view();
        }
    }

    //修改投诉信息
    public function edit() {
        if (input('post.')) {
            $data = input('post.');
            $data['admin_id']   = session('admin_id');
            $data['admin_name'] = session('admin_name');
            $data['update_time'] = time();
            $complain_id = Db::name('complain_message')->where(['complain_id'=>$data['complain_id']])->update($data);
            if($complain_id){
                echo ajax_success('提交成功');
            }else{
                echo ajax_error('提交失败');
            }
        } else {
            //查询投诉信息
            $complain_id = input('get.complain_id');
            $result = Db::name('complain_message')->where(['complain_id'=>$complain_id])->find();
            $this->assign('result',$result);
            return view();
        }
    }
}
